import javax.sound.sampled.*;
import java.io.*;
import java.net.*;

public class Sender {
    private static final String SERVER_IP = "47.76.72.147"; // 更改为你的服务器IP
    private static final int SERVER_PORT = 5000;

    public static void main(String[] args) {
        try (Socket socket = new Socket(SERVER_IP, SERVER_PORT);
             OutputStream output = socket.getOutputStream();
             TargetDataLine microphone = AudioUtil.getTargetDataLine()) {

            microphone.start();

            byte[] buffer = new byte[1024];
            int numBytesRead;
            while (true) {
                numBytesRead = microphone.read(buffer, 0, buffer.length);
                if (numBytesRead == -1) break;
                output.write(buffer, 0, numBytesRead);
            }
        } catch (IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }
}
